#include <GL/gl.h>
#include <new>

#include "Class/Manager/Graphics.hpp"

namespace		Manager
{
  bool			Graphics::Open()
  {
	if (!this->_isValid || !this->_Window || !(this->_Window = new (std::nothrow) sf::RenderWindow))
	  return ((this->_isValid = false));
	else if (this->_Window->IsOpened())
	  return (false);

	this->_Window->Create(sf::VideoMode(this->_Config.Width(), this->_Config.Height(), this->_Config.Color()),
						  this->_Config.Caption(), this->_Config.Windowed() ? sf::Style::Close : sf::Style::Fullscreen);
	this->_Window->SetFramerateLimit(this->_Config.Framerate());
	this->_Window->UseVerticalSync(this->_Config.VSync());
	this->_Window->PreserveOpenGLStates(this->_Config.OpenGL());

	if (this->_Config.OpenGL())
	  {
		glEnable(GL_DEPTH_TEST);
		/*		glEnable(GL_BLEND);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
		glEnable(GL_TEXTURE_2D);
/*		glActiveTexture(GL_TEXTURE0);*/
	  }

	this->Clear();
	this->Display();

	return ((this->_isValid = this->_Window->IsOpened()));
  }
  bool			Graphics::ReOpen()
  {
	this->Close();
	return (this->Open());
  }

  bool			Graphics::Close()
  {
	if (!this->_Window || !this->_Window->IsOpened())
	  return (false);

	this->_Window->Close();
	return (true);
  }
}
